<?php

class m130726_092815_create_table_user_and_role extends CDbMigration
{
        /*
	public function up()
	{
	}

	public function down()
	{
		echo "m130726_092815_create_table_user_and_role does not support migration down.\n";
		return false;
	}*/

	
	// Use safeUp/safeDown to do migration with transaction
	public function safeUp()
	{
                $this->execute("
                        CREATE TABLE IF NOT EXISTS `roles` (
                            `id` int(11) NOT NULL AUTO_INCREMENT,
                            `name` varchar(200) CHARACTER SET utf8 NOT NULL,
                            PRIMARY KEY (`id`)
                        ) ENGINE=InnoDB  DEFAULT CHARSET=latin1

                ");
                
                $this->execute("
                        INSERT INTO `roles` (`id`, `name`) VALUES (1, 'Admin')
                ");
                
                
                //table users
                $this->execute("
                        CREATE TABLE IF NOT EXISTS `users` (
                                `id` int(11) NOT NULL AUTO_INCREMENT,
                                `username` varchar(255) CHARACTER SET utf8 NOT NULL,
                                `password` varchar(128) NOT NULL,
                                `email` varchar(255) NOT NULL,
                                `roleId` int(11) NOT NULL,
                                `createdTime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
                                PRIMARY KEY (`id`)
                        ) ENGINE=InnoDB  DEFAULT CHARSET=latin1;
                ");
                
                $this->execute("
                        INSERT INTO `users` (`username`, `password`, `email`, `roleId`) VALUES
                                ('admin', '21232f297a57a5a743894a0e4a801fc3', 'admin@example.com', 1)
                ");
	}

	public function safeDown()
	{
	}
	
}